<%--
  Created by IntelliJ IDEA.
  User: deng
  Date: 2021/3/14
  Time: 13:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%String path = request.getContextPath();%>
<%String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";%>
<html>
<head>
    <title>新增宠物</title>
    <script src="jquery-1.12.4.js"></script>
</head>
<body>
<form action="<%=basePath%>addPet" method="post" id="form1">
    <table>
        <tr>
            昵称:<input type="text" name="name" id="name"/></br>
        </tr>
        <tr>
            品种:
            <select  name="breed">
                <option value="---请选择---">---请选择---</option>
                <option value="狗">狗</option>
                <option value="猫">猫</option>
                <option value="鸟">鸟</option>
                <option value="兔">兔</option>
            </select></br>
        </tr>
        <br>
        <input type="radio" name="sex" value="雄" checked/>雄
        <input type="radio" name="sex" value="雌"/>雌</br>
        </tr>
        <tr>
            出生日期<input type="text" name="date" id="date"/>yyyy-mm-dd</br>
        </tr>
        <tr>
            宠物描述:
            <textarea style="font-size: 18px" cols="10" rows="4" name="Description">

                </textarea></br>
        </tr>
        <tr>
            <input type="submit" value="提交"/>&nbsp;<input type="reset" value="重置"/>
        </tr>
    </table>
</form>
<script type="text/javascript">
    $(function () {
        $("#form1").submit(function () {
            var name=$("#name").val();
            if (""==name){
                alert("昵称不能为空!");
                return false;
            };
            var pin=$("select :selected").val();
            if ("---请选择---"==pin){
                alert("请选择品种!");
                return  false;
            };

            var date=$("#date").val();
            var reg=/^\d{4}\-\d{1,2}\-\d{1,2}$/;
            if (!reg.test(date)){
                alert("请输入正确的出身日期格式!");
                return false;
            }
        })
    })
</script>
</body>
</html>
